package com.sgb.kjwl.utils

import android.text.TextUtils
import java.util.regex.Pattern

object ReplaceUtils {
    /**
     * 图文混排加br 不加的话 文字好像不显示
     * @param body 需要替换的富文本数据
     * @return
     */
     fun getHtml(body: String?): String {
        if (TextUtils.isEmpty(body)){
            return ""
        }
        var body = body
        var regex = "<img.*src\\s*=\\s*(.*?)[^>]*?>"
        regex = "<\\s*img(.+?)src=[\"'](.*?)[\"']\\s*/?\\s*>" //匹配一个标签
        // 搜索<img>标签的字符串
        val pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
        val matcher = pattern.matcher(body)
        while (matcher.find()) {
            val one = matcher.group(0)
            body = body!!.replace(one, "<br>$one<br>")
        }
        return body!!
    }
}